from django.db import models
from django.utils.encoding import *
from django.contrib.auth.models import User


class Book(models.Model):
    book_id = models.AutoField(primary_key=True)
    volume_id = models.IntegerField()
    book_title = models.CharField(max_length=22)
    book_title_long = models.CharField(max_length=59)
    book_title_short = models.CharField(max_length=8)
    book_title_jst = models.CharField(max_length=27)
    book_subtitle = models.CharField(max_length=80)
    book_title_long = models.CharField(max_length=59)
    lds_org = models.CharField(max_length=6)
    num_chapters = models.IntegerField()
    num_verses = models.IntegerField()

class Verse(models.Model):
    verse_id = models.AutoField(primary_key=True)
    book_id = models.ForeignKey(Book)
    chapter = models.IntegerField()
    verse = models.IntegerField()
    pilcrow = models.IntegerField()
    verse_scripture =  models.TextField()
    verse_title = models.CharField(max_length=30)
    verse_title_short = models.CharField(max_length=30)
    
    def get_reference(self):
        return str(self.book_id.book_title_short) + " " + str(self.chapter) + ":" + str(self.verse)
    
    def __unicode__(self):
        return self.get_reference()
   
class Game(models.Model):
    uid = models.ForeignKey(User)
    date = models.DateTimeField(auto_now=False, auto_now_add=True)
    won = models.BooleanField()
    
#class Scripture(models.Model):
#    sid = models.AutoField(primary_key=True)
#    text = models.TextField()
#    ref = models.CharField(max_length=100)
#    
#    def __unicode__(self):
#        return self.ref
#    
#    def get_excerp(self):
#        value = unicode(self.text)
#        if len(value) < 80:
#            return value
#        
#        value = value[:80]
#        words = value.split(' ')[:-1]
#        return ' ' . join(words) + '...'
